

import BaseObject from './base-object'

import { reactive } from 'vue'

import type {
  IStateKey  
} from '../types/type'

/**
 * 给 BaseObject 套个壳，加上 reactive 实现响应性。
 * @param fun 必须使用函数
 * @param id 标识，记录日志用
 * @param isLog 是否记录日志
 * @returns 
 */
export default function createModel<T extends object>(
    fun: T | (() => T),
    id: IStateKey = Symbol('_object'),
    isLog = false
  ) {
    const re = new BaseObject<T>(fun, id, isLog)
    const ret = reactive(re)
    return ret as BaseObject<T> & T
  }